import json

from django.urls import path

from valar.classes.valar_response import ValarResponse
from valar.dao import Dao

from calculater.models.panel import InputPanel
from calculater.views import (
    test_request,
    calculate_bio_jet_fuel_emissions,
    create_production_batch,
    # 润滑脂计算器
    create_lubricating_grease_batch,
    calculate_lubricating_grease_emissions,
)


# def test_request(request):
#     body = json.loads(request.body)
#     _id = body.get('panel_id')
#     dao = Dao('calculater.InputPanel')
#     panel: InputPanel = dao.find_one(_id)
#     values = panel.inputmaterial_set.all().values("category","value")
#     total = sum([v['value'] for v in values])
#
#     r_dao = Dao('calculater.Result')
#     r_dao.save_one({
#         "panel_id": _id, "value": total
#     })
#     return ValarResponse(True)


urlpatterns = [
    # 原有简单计算接口
    path('test', test_request),
    
    # 生物航空煤油碳足迹计算接口（已注释）
    # path('bio-jet-fuel/calculate', calculate_bio_jet_fuel_emissions, name='calculate_bio_jet_fuel_emissions'),
    # path('bio-jet-fuel/create-batch', create_production_batch, name='create_production_batch'),
    
    # 润滑脂碳足迹计算接口
    path('lubricating-grease/calculate', calculate_lubricating_grease_emissions, name='calculate_lubricating_grease_emissions'),
]
